package org.tangerinejunction.imstats.sandbox;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.tangerinejunction.imstats.util.Pair;

public class WordFreqTable {
  HashMap<String, Integer> distinctWords = new LinkedHashMap<String, Integer>();
  long total = 0;
  public void add(String w) {
    total++;
    Integer i = distinctWords.get(w);
    distinctWords.put(w, i== null ? 1 : i+1);
  }
  
  public ArrayList<Pair<String,Integer>> get() {
    ArrayList<Pair<String,Integer>> res = new ArrayList<Pair<String,Integer>>();
    for(Map.Entry<String, Integer> e: distinctWords.entrySet())
      res.add(new Pair<String,Integer>(e.getKey(), e.getValue()));
    return res;
  }

  public long total() {
    return total;
  }

  public int distinct() {
    return distinctWords.size();
  }
  
}
